package com.plm.mr.reducejoin;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * Reduce Join
 * 这种方式中，合并的操作是在 Reduce 阶段完成，Reduce 端的处理压力太大，Map
 * 节点的运算负载则很低，资源利用率不高，且在 Reduce 阶段极易产生数据倾斜
 * 解决方案：Map 端实现数据合并。
 */
public class TableDriver {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        args = new String[]{"E:\\projects\\hadoop\\fs-input\\inputtable", "E:\\projects\\hadoop\\fs-output\\output3"};

        Configuration conf = new Configuration();
        Job job = Job.getInstance();

        job.setJarByClass(TableDriver.class);
        job.setMapperClass(TableMapper.class);
        job.setReducerClass(TableReducer.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(TableBean.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(TableBean.class);

        FileInputFormat.setInputPaths(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path((args[1])));

        boolean b = job.waitForCompletion(true);
        System.exit(b ? 0 : 1);
    }
}
